package com.lds.register.center.server.business.appinstance.controller;

import com.lds.management.center.common.model.db.OrderBy;
import com.lds.management.center.common.model.db.PageResult;
import com.lds.management.center.common.model.dto.ResultDTO;
import com.lds.register.center.common.model.appinstance.request.AppInstanceBaseBatchCreateRequest;
import com.lds.register.center.common.model.appinstance.request.AppInstanceBaseBatchDeleteRequest;
import com.lds.register.center.common.model.appinstance.request.AppInstanceBaseBatchUpdateRequest;
import com.lds.register.center.common.model.appinstance.request.AppInstanceBaseCreateRequest;
import com.lds.register.center.common.model.appinstance.request.AppInstanceBaseDeleteRequest;
import com.lds.register.center.common.model.appinstance.request.AppInstanceBaseGetByIdRequest;
import com.lds.register.center.common.model.appinstance.request.AppInstanceBaseGetByIdsRequest;
import com.lds.register.center.common.model.appinstance.request.AppInstanceBaseGetByKeyRequest;
import com.lds.register.center.common.model.appinstance.request.AppInstanceBaseListPageRequest;
import com.lds.register.center.common.model.appinstance.request.AppInstanceBaseListRequest;
import com.lds.register.center.common.model.appinstance.request.AppInstanceBaseUpdateRequest;
import com.lds.register.center.common.model.appinstance.response.AppInstanceBaseBatchCreateResponse;
import com.lds.register.center.common.model.appinstance.response.AppInstanceBaseBatchDeleteResponse;
import com.lds.register.center.common.model.appinstance.response.AppInstanceBaseBatchUpdateResponse;
import com.lds.register.center.common.model.appinstance.response.AppInstanceBaseDeleteResponse;
import com.lds.register.center.common.model.appinstance.response.AppInstanceBaseListResponse;
import com.lds.register.center.common.model.appinstance.response.AppInstanceBaseResponse;
import com.lds.register.center.server.business.appinstance.service.AppInstanceBaseService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础前端控制器
 *
 * @author lidongsheng
 * @since 2025-07-16
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/common/app_instance")
public class AppInstanceBaseController {
    private final AppInstanceBaseService appInstanceBaseService;

    /**
     * 创建
     */
    @PostMapping("/create")
    public ResultDTO<AppInstanceBaseResponse> createAppInstance(@RequestBody @Validated AppInstanceBaseCreateRequest request) {
        return appInstanceBaseService.createAppInstance(request);
    }

    /**
     * 批量创建
     */
    @PostMapping("/batch-create")
    ResultDTO<AppInstanceBaseBatchCreateResponse> batchCreateAppInstance(@RequestBody @Validated AppInstanceBaseBatchCreateRequest request) {
        return appInstanceBaseService.batchCreateAppInstance(request);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    ResultDTO<AppInstanceBaseDeleteResponse> deleteAppInstance(@RequestBody AppInstanceBaseDeleteRequest request) {
        return appInstanceBaseService.deleteAppInstance(request);
    }

    /**
     * 批量删除
     */
    @PostMapping("/batch-delete")
    ResultDTO<AppInstanceBaseBatchDeleteResponse> batchDeleteAppInstance(@RequestBody @Validated AppInstanceBaseBatchDeleteRequest request) {
        return appInstanceBaseService.batchDeleteAppInstance(request);
    }

    /**
     * 更新
     */
    @PostMapping("/update")
    ResultDTO<AppInstanceBaseResponse> updateAppInstance(@RequestBody @Validated AppInstanceBaseUpdateRequest request) {
        return appInstanceBaseService.updateAppInstance(request);
    }

    /**
     * 批量更新
     */
    @PostMapping("/batch-update")
    ResultDTO<AppInstanceBaseBatchUpdateResponse> batchUpdateAppInstance(@RequestBody @Validated AppInstanceBaseBatchUpdateRequest request) {
        return appInstanceBaseService.batchUpdateAppInstance(request);
    }

    /**
     * 查询
     */
    @PostMapping("/list")
    ResultDTO<AppInstanceBaseListResponse> listAppInstance(@RequestBody AppInstanceBaseListRequest request) {
        return appInstanceBaseService.listAppInstance(request);
    }

    /**
     * 查询所有
     */
    @PostMapping("/list-all")
    ResultDTO<AppInstanceBaseListResponse> listAllAppInstance(@RequestBody OrderBy orderBy) {
        return appInstanceBaseService.listAllAppInstance(orderBy);
    }

    /**
     * 根据ID查询
     */
    @PostMapping("/get")
    ResultDTO<AppInstanceBaseResponse> getAppInstanceById(@RequestBody @Validated AppInstanceBaseGetByIdRequest request) {
        return appInstanceBaseService.getAppInstanceById(request);
    }

    /**
     * 根据ID集合查询
     */
    @PostMapping("/gets")
    ResultDTO<AppInstanceBaseListResponse> getAppInstanceByIds(@RequestBody @Validated AppInstanceBaseGetByIdsRequest request) {
        return appInstanceBaseService.getAppInstanceByIds(request);
    }

    /**
     * 分页查询
     */
    @PostMapping("/list-page")
    ResultDTO<PageResult<AppInstanceBaseResponse>> listAppInstancePage(@RequestBody AppInstanceBaseListPageRequest request) {
        return appInstanceBaseService.listAppInstancePage(request);
    }

    /**
     * 业务主键对应数据是否存在
     */
    @PostMapping("/isExist")
    public ResultDTO<Boolean> isExist(@RequestBody @Validated AppInstanceBaseGetByKeyRequest request) {
        return ResultDTO.success(appInstanceBaseService.getAppInstanceByKey(request) != null);
    }

    /**
     * 异步批量创建 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-create-async")
    ResultDTO<AppInstanceBaseBatchCreateResponse> batchCreateAppInstanceAsync(@RequestBody @Validated AppInstanceBaseBatchCreateRequest request) {
        return appInstanceBaseService.batchCreateAppInstanceAsync(request);
    }

    /**
     * 异步批量删除 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-delete-async")
    ResultDTO<AppInstanceBaseBatchDeleteResponse> batchDeleteAppInstanceAsync(@RequestBody @Validated AppInstanceBaseBatchDeleteRequest request) {
        return appInstanceBaseService.batchDeleteAppInstanceAsync(request);
    }

    /**
     * 异步批量更新 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-update-async")
    ResultDTO<AppInstanceBaseBatchUpdateResponse> batchUpdateAppInstanceAsync(@RequestBody @Validated AppInstanceBaseBatchUpdateRequest request) {
        return appInstanceBaseService.batchUpdateAppInstanceAsync(request);
    }

}